package org.netty.push.server.message.handler;

import java.util.ArrayList;
import java.util.List;

import org.netty.push.core.proto.BaseMessage;
import org.netty.push.core.proto.handler.MessageHandler;
import org.netty.push.core.proto.handler.MessageHandlerManager;
import org.netty.push.core.proto.handler.PingHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import io.netty.channel.ChannelHandlerContext;
/**
 * 消息处理
 * @author zzh
 *
 */
@SuppressWarnings("all")
@Component
public class DefaultMessageHanderManger implements MessageHandlerManager {


//	private List<MessageHandler> messageHandlers=new ArrayList<MessageHandler>();
	
	@Autowired
	private List<MessageHandler> messageHandlers=new ArrayList<MessageHandler>();
	
	public DefaultMessageHanderManger(){
		PingHandler pingHandler=new PingHandler();
		messageHandlers.add(pingHandler);
	}
	
	@Override
	public void handle(ChannelHandlerContext ctx, BaseMessage msg) {
		messageHandlers.forEach(handler->{
			if(handler.supported(msg)) {
				handler.handle(ctx, msg);
			}
		});
		
	}

	@Override
	public List<MessageHandler> getMessageHander() {
		return messageHandlers;
	}

}
